/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-12-10     Administrator       the first version
 */
#include "DevManager.h"
#include "GlobalVar.h"

/*********************
 * Unified management of device labels
 * 0-50  step motor device
 * 51-100 io out device
 * 101-120 pwm motor device
 * 121-200 sensor
 * 201-255 other device
 *********************/

/** Query of the device name.  */
char* QueryOfDevName(int dev_num)
{
    return (char*)&(dev_info[dev_num].dev_name);
}

/** Query of the device driver num.   */
uint8_t QueryOfDevDriverNum(int dev_num)
{
    return dev_info[dev_num].dirver_num;
}

/** Query of the device which board belong to.  */
uint8_t QueryOfDevBoardNum(int dev_num)
{
    return dev_info[dev_num].board_addr;
}

/** Check whether the device is on my board. */
uint8_t MyBoardDev(int dev_num)
{
    int boardNum = QueryOfDevBoardNum(dev_num);
    if(boardNum == machine_info.address)
    {
        return true;
    }
    return false;
}

/**  Query of the device what kind of.    */
uint8_t QueryOfDevType(int dev_num)
{
    return dev_info[dev_num].devType;
}

uint8_t QueryOfDevCircleOptimize(int dev_num)
{
    return motor_info[dev_num].circle_optimize;
}

uint8_t QueryOfDevFineFraction(int dev_num)
{
    return motor_info[dev_num].fine_fraction;
}

uint32_t QueryOfDevStepPerRevolution(int dev_num)
{
    return motor_info[dev_num].step_per_revolution;
}

uint32_t QueryOfDevUStepPerRevolution(int dev_num)
{
    return (motor_info[dev_num].step_per_revolution * motor_info[dev_num].fine_fraction);
}



/*********************
 * dummy motor manager
 *********************/
uint32_t scaler[TOTAL_MOTOR_NUM][20] ={0};


uint32_t position_model_calculator(uint8_t dev_num,uint8_t position_dot)
{
    switch (dev_num) {
        case 1:
        case 2:

            break;

        default:
            return scaler[dev_num][position_dot];
            break;
    }
    return 0;
}


uint32_t position_scaler(uint8_t dev_num,uint8_t position_dot)
{
    return scaler[dev_num][position_dot];
}


MOTOR_SPD dummy_motor_spd[TOTAL_MOTOR_NUM][10];

void QueryOfDevSpd(uint8_t devNo,uint8_t Speed_select,MOTOR_SPD *temp)
{
    temp->a1 =  dummy_motor_spd[devNo][Speed_select].a1;
    temp->amax =  dummy_motor_spd[devNo][Speed_select].amax;
    temp->d1 =  dummy_motor_spd[devNo][Speed_select].d1;
    temp->dmax =  dummy_motor_spd[devNo][Speed_select].dmax;
    temp->v1 =  dummy_motor_spd[devNo][Speed_select].v1;
    temp->vmax =  dummy_motor_spd[devNo][Speed_select].vmax;
    temp->vstart =  dummy_motor_spd[devNo][Speed_select].vstart;
    temp->vstop =  dummy_motor_spd[devNo][Speed_select].vstop;
}












